package model

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type Appointment struct {
	Id                uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	UserId            uint           `gorm:"column:user_id;type:bigint(20);comment:用户ID;not null;" json:"user_id"`                                                                  // 用户ID
	CourseId          uint           `gorm:"column:course_id;type:bigint(20);comment:课程ID;not null;" json:"course_id"`                                                              // 课程ID
	AppointmentStatus uint           `gorm:"column:appointment_status;type:tinyint(1) UNSIGNED;comment:预约状态:1:待预约，2:代付款，3:已预约，4:已完成;not null;default:1;" json:"appointment_status"` // 预约状态:1:待预约，2:代付款，3:已预约，4:已完成
	CreatedAt         time.Time      `gorm:"column:created_at;type:datetime(3);not null;" json:"created_at"`
	UpdatedAt         time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt         gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (a *Appointment) TableName() string {
	return "appointment"
}
func (a *Appointment) Create() error { //创建预约
	return config.DB.Create(&a).Error
}
func (a *Appointment) Delete() error {
	return config.DB.Where("id = ?", a.Id).Delete(&a).Error
}
